<?php
require_once BACKGROUND_COMMON_ACTION_SERVICE_DIR . '/default.php';

class background_good_edit_action_service extends background_default_common_action_service
{
    protected static $_instance;

    public static function get_instance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }


    protected function _current_page_process()
    {                	
        $result = array('status' => 0, 'message' => '', 'data' => array());
	     
	    $id = init_user_data_key($_GET, 'id', 'int');
	
	    $model_background_good = wwy_resource_container::get_model_background_good();
	     
	    $good_info = $model_background_good->find($id);
	    //var_dump($good_info); exit();
	    if(empty($good_info)){
	        $result['status']  = -400;
	        $result['message'] = '该商品不存在';
	    }else{
    	    
    	    //获取动态属性
    	    $where = array('good_id' => $id);
    	    $order = array('`order` asc');
    	    $attr_list = $model_background_good->get_attr_list($where, $order);
    	    $good_info['attr_list'] = $attr_list;
    	    
    	    //获取规格动态属性
    	    $where = array('good_id' => $id);
    	    $order = array('`order` asc');
    	    $sattr_list = $model_background_good->get_sattr_list($where, $order);
    	    $good_info['sattr_list'] = $sattr_list;	
    	    
    	    //获取数量范围
    	    $where = array('good_id' => $id);
    	    $order = array('`order` asc');
    	    $number_grade_list = $model_background_good->get_number_grade_list($where, $order);
    	    $good_info['number_grade_list'] = $number_grade_list;        	    
    	    
    	    //获取规格
    	    $where = array('good_id' => $id);
    	    $order = array('`order` asc');
    	    $spec_list = $model_background_good->get_spec_list($where, $order);
    	    //var_dump($spec_list); exit();
    	    $good_info['spec_list'] = $spec_list;
    	
    	    $model_background_good_category = wwy_resource_container::get_model_background_good_category();
    	    $all_category_list = $model_background_good_category->get_all_category_list();
    	    
    	    $timestamp = time();                                   //上传图片验证的时间戳
    	    $uploadify_key = wwy_resource_container::get_config_item('uploadify_key');
    	    $token     = md5($timestamp . $uploadify_key);   //上传图片验证的令牌
    	    
    	    //控制是否引用【uploadify】、【ueditor】相关
    	    $if_good_info = 1;
    	    
    	    self::add_view_data('good_info', $good_info);
    	    self::add_view_data('all_category_list', $all_category_list);
    	    self::add_view_data('timestamp', $timestamp);
    	    self::add_view_data('token', $token);
    	    self::add_view_data('if_good_info', $if_good_info);
	    }
	
	    self::set_view_status($result['status']);
	    self::set_view_message($result['message']);
    }
}